<template>
	<!-- 上传页 -->
	<view class="u-demo">
		<!--合同签署页-->
		<view class="bgfff con back " v-if="isType==1 || isType==2 && state == 3  ">
			<!-- 已拒绝或已通过 -->
			<text class="title f28" v-if="state == 0 || state == 2 || state == 1">合同模版</text>
			<text class="title f28" v-if="state == 3">已签署合同</text>
			<view class="flex flex-align-center flex-pack-justify item f26 Jbetween" style="">
				<!-- flex-align-center -->
				<view class=" " style="display: flex;flex-direction: column;">
					<view class="">
						<image src="../static/pdf.png"></image>
						<text v-if="state == 0 || state == 2 || state == 1">合同模版</text>
						<text v-if="state == 3">已签署合同</text>
					</view>
					<view class="" style="font-size: 25rpx;font-weight: bold;margin-top: 20rpx;">
						更新时间： {{updateTime}}
					</view>
				</view>
				<uni-transition :duration="1500" :mode-class="'slide-right'" :show="true">
					<button style="width: 160rpx;" class="down text24 white button fontWeight" @click="downLoadChange"
						:loading="loading">下载</button>
				</uni-transition>
			</view>
		</view>
		<!-- 未上传 -->
		<view class="" v-if="isType==2&&user_type=='自然人'">
			<view class="bgfff con back " v-if="state == 0 || state == 2">
				<text class="title f28">电子合同签署</text>
				<view class="flex flex-align-center flex-pack-justify item f26">
					<view class="flex flex-align-center">
						<image src="../static/pdf.png"></image>
						电子合同签署
					</view>
				</view>
				<view class="state flex" style="display: flex;flex-direction: column;">
					<!-- 拒绝原因 -->
					<view class="text-left text30" style="color: red;font-size: 28rpx;" v-if="state ==2">
						审核失败原因:{{content}}</view>
					<uni-transition :duration="400" :mode-class="'slide-right'" :show="true">
						<view style="display:flex;justify-content:flex-end;">
							<view class="down f26 c666 " style="margin-bottom:20rpx;" v-if="state==0">
								<button class="down text24 white fontWeight button"
									style="margin-right:10rpx;width: 100%;" @click="uploadAutographChange"
									:loading="loading">电子签</button>
							</view>
							<button class="down  text24 white fontWeight button" style="margin-right:10rpx;width: 100%;"
								@click="uploadAutographChange" v-if="state == 2">重新电子签</button>
						</view>
					</uni-transition>
				</view>
			</view>
		</view>
		<!-- 未上传 -->
		<view class="" v-if="isType==1">
			<view class="bgfff con back " v-if="state == 0 || state == 2">
				<text class="title f28">纸质合同签署</text>
				<view class="flex flex-align-center flex-pack-justify item f26">
					<view class="flex flex-align-center">
						<image src="../static/pdf.png"></image>
						纸质合同签署
					</view>
				</view>
				<view class="state flex" style="display: flex;flex-direction: column;">
					<uni-transition :duration="600" :mode-class="'slide-left'" :show="true">
						<view class="text-left text30" style="color:red;font-size:28rpx;" v-if="state==2">
							{{'审核失败原因:'+content}}</view>
					</uni-transition>
					<view class="text-left text20 " style="color:#999999;margin-top:20rpx;">只能上传doc,docx, pdf, png,
						jpg或jpeg格式文件</view>
					<uni-transition :duration="1500" :mode-class="'slide-right'" :show="true">
						<view style="display:flex;justify-content:flex-end;">
							<view class="down f26 c666 " style="margin-bottom:20rpx;" v-if="state==0">
								<button class="down text24 white fontWeight button"
									style="margin-right:10rpx;width: 100%;" @click="uploadFileChange"
									:loading="loading">上传合同</button>
							</view>
							<button class="down text24 white fontWeight button" @click="uploadFileChange"
								v-if="state == 2" :loading="loading"
								style="margin-right:10rpx;width: 35%;">重新上传合同</button>
						</view>
					</uni-transition>
				</view>
			</view>
		</view>

		<!-- 待审核 -->
		<view class="bgfff con back" v-if="state == 1">
			<text class="title f28">合同签署</text>
			<view class="flex flex-align-center flex-pack-justify item f26">
				<view class="flex flex-align-center">
					<image src="../static/pdf.png"></image>合同签署
				</view>
			</view>
			<uni-transition :duration="1500" :mode-class="'slide-right'" :show="true">
				<view class=" flex text-center" style="display: flex;justify-content: flex-end;padding-right:20rpx">
					<button style="width: 160rpx;background-color: #bcbcbc;color: #303133;"
						class="down text24 fontWeight">审核中</button>
				</view>
			</uni-transition>
		</view>
		<!-- 下载弹窗 -->
		<u-popup width="95%"
			custom-style="border-bottom-left-radius:20rpx;border-bottom-right-radius:20rpx;border-top-right-radius:20rpx;border-top-left-radius:20rpx;"
			v-model="isShowDownLoad" mode="center" closeable>
			<view>
				<text
					style="color: rgb(71, 70, 70); font-weight: bold; font-size: 30rpx; margin-top: 70rpx; margin-left: 20rpx; margin-right: 20rpx; display: block">
					为付款和生成合同需要，请填写以下信息
				</text>
				<!-- 				   label设置左侧内容，label-width设置label的宽度，******************************************************************************8888888888
				   prop很重要！是验证是否有效的重要属性。******************************************************************************8888888888
				   且避坑点是，这个prop只能写在u-form-item标签里，写在u-input里无效******************************************************************************8888888888
 -->
				<form @submit="formSubmit" @reset="formReset">
					<view class="item p_r" style="width: 600rpx">
						<text class="f24" style="font-size: 28rpx">
							<text style="font-size: 28rpx; color: red">*</text>
							户名
						</text>
						<input placeholder-style="font-size:26rpx" type="text" placeholder="请输入姓名" class="f28"
							name="name" />
					</view>
					<view class="item p_r" style="width: 600rpx">
						<text class="f24" style="font-size: 28rpx">
							<text style="font-size: 28rpx; color: red; margin-right: 10rpx">*</text>
							户名身份证号
						</text>
						<input placeholder-style="font-size:26rpx" type="text" placeholder="请输入身份证号" class="f28"
							name="idcard" />
					</view>
					<view class="item p_r" style="width: 600rpx">
						<text class="f24" style="font-size: 28rpx">
							<text style="font-size: 28rpx; color: red">*</text>
							银行账号
						</text>
						<input placeholder-style="font-size:26rpx" type="text" placeholder="请输入账号" class="f28"
							name="account" />
					</view>
					<view class="item p_r" style="width: 600rpx">
						<text class="f24" style="font-size: 28rpx">
							<text style="font-size: 28rpx; color: red">*</text>
							开户行（请填写完整银行开户行，如：***银行****支行）
						</text>
						<input placeholder-style="font-size:26rpx" type="text" placeholder="请输入开户行" class="f28"
							name="deposit" />
					</view>
					<uni-transition :duration="600" :mode-class="'slide-bottom'" :show="transhow">
						<view style="padding: 20rpx; margin-top: 10rpx">
							<button style="width: 100%" class="subbutton" formType="submit">确定</button>
						</view>
					</uni-transition>
				</form>
			</view>
		</u-popup>
		<!-- 合同签署流程 -->
		<view class="content" style="background-color: #FFFFFF;margin: 0 30rpx;padding: 20rpx 20rpx;">
			<view v-if="isType==1">
				<uni-transition :duration="1300" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor fontWeight" style="margin-bottom: 10rpx;">签署合同流程:</view>
				</uni-transition>
				<uni-transition :duration="1400" :mode-class="'slide-bottom'" :show="true">
					<view v-if="user_type=='自然人'" class=" fontColor" style="margin-bottom: 10rpx;">
						第{{user_type=='自然人'?'一':''}}步 填写后期服务费支付的银行账号</view>
				</uni-transition>
				<uni-transition :duration="1500" :mode-class="'slide-bottom'" :show="true">
					<view v-if="user_type=='自然人' || user_type=='法人' || user_type=='联络人'" class=" fontColor"
						style="margin-bottom: 10rpx;">第{{user_type=='自然人'?'二':'一'}}步 下载并打印合同</view>
				</uni-transition>
				<uni-transition :duration="1600" :mode-class="'slide-bottom'" :show="true">
					<view v-if="user_type=='自然人' || user_type=='法人' || user_type=='联络人'" class=" fontColor"
						style="margin-bottom: 10rpx;">第{{user_type=='自然人'?'三':'二'}}步 将合同内容填写完整并签字</view>
				</uni-transition>
				<uni-transition :duration="1700" :mode-class="'slide-bottom'" :show="true">
					<view v-if="user_type=='自然人' || user_type=='法人' || user_type=='联络人'" class=" fontColor"
						style="margin-bottom: 10rpx;">第{{user_type=='自然人'?'四':'三'}}步 将合同以照片或PDF格式上传小程序</view>
				</uni-transition>
				<uni-transition :duration="1800" :mode-class="'slide-bottom'" :show="true">
					<view v-if="user_type=='自然人' || user_type=='法人' || user_type=='联络人'" class=" fontColor"
						style="margin-bottom: 10rpx;">第{{user_type=='自然人'?'五':'四'}}步 等待甲方签署</view>
				</uni-transition>
				<uni-transition :duration="1900" :mode-class="'slide-bottom'" :show="true">
					<view v-if="user_type=='自然人' || user_type=='法人' || user_type=='联络人'" class=" fontColor"
						style="margin-bottom: 10rpx;">第{{user_type=='自然人'?'六':'五'}}步 双方合同签署完成</view>
				</uni-transition>
				<uni-transition :duration="2000" :mode-class="'slide-bottom'" :show="true">
					<view v-if="user_type=='自然人' || user_type=='法人' " class=" fontColor ">注：有问题联系本人联络人（点击我的→头像下方联络人）
					</view>
				</uni-transition>
			</view>
			<view v-if="isType==2">
				<uni-transition :duration="1300" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor fontWeight" style="margin-bottom:10rpx;">电子合同签署流程:</view>
				</uni-transition>
				<uni-transition :duration="1400" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor" style="margin-bottom:10rpx;" v-if="user_type=='自然人'">第一步
						选择电子合同签署方式进入合同模板选择页</view>
				</uni-transition>
				<uni-transition :duration="1500" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor" style="margin-bottom:10rpx;" v-if="user_type=='自然人'">第二步
						根据本人情况选择其中一份合同模板并点击签署</view>
				</uni-transition>
				<uni-transition :duration="1600" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor" style="margin-bottom:10rpx;" v-if="user_type=='自然人'">第三步
						请填写弹框中乙方相关信息、后期服务费支付的银行账户等内容，生成本人完整合同</view>
				</uni-transition>
				<uni-transition :duration="1700" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor" style="margin-bottom:10rpx;" v-if="user_type=='自然人'">第四步
						进入电子合同页，点击右下方签署按钮进行线上合同签名</view>
				</uni-transition>
				<uni-transition :duration="1800" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor" style="margin-bottom:10rpx;" v-if="user_type=='自然人'">第五步 签署完成后，点击上传合同
					</view>
				</uni-transition>
				<uni-transition :duration="1900" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor" style="margin-bottom:10rpx;" v-if="user_type=='自然人'">第六步 等待甲方签署</view>
				</uni-transition>
				<uni-transition :duration="2000" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor" style="margin-bottom:10rpx;" v-if="user_type=='自然人'">第七步 双方合同签署完成</view>
				</uni-transition>
				<uni-transition :duration="2100" :mode-class="'slide-bottom'" :show="true">
					<view class=" fontColor" style="margin-top:20rpx;" v-if="user_type=='自然人'">
						注：有问题联系本人联络人（点击我的→头像下方联络人）</view>
				</uni-transition>
			</view>
		</view>
	</view>
</template>

<script>
	import Validate from '../../../utils/util.js';
	export default {
		data() {
			return {
				updateTime: "", //更新时间
				transhow: false,
				// action: 'https://jizhang.xqyu.cn/index.php/api/index/upload',
				isType: "", //点击的是电子合同.还是纸质合同
				// 审核中，待上传或  审核通过后的状态
				status: 2,
				// 用户信息
				userInfo: '',
				pageCount: '', //图片上传张数
				// 上传成功与否的状态
				contract_one: '',
				contract_two: '',
				content: '暂无',
				// type  0未上传 1待审核 2已拒绝 3已通过
				state: {},
				//  上传合同模板需要传递的参数
				uid: '',
				user_type: '',
				phone: '',
				fileReal: '',
				// 是否显示下载弹窗
				isShowDownLoad: false,
				// 户名输入框是否禁止输入
				isDisabled: false,
				form: { //form表单数据
					inputValueName: '', //姓名
					idcard: '', //身份证号
					account: '', //银行账号
					deposit: '' //开户行
				},
				// 表单校验规则
				rules: {
					inputValueName: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式
						trigger: 'blur'
					}],
					idcard: [{
						required: true,
						min: 5,
						message: '请输入身份证号',
						trigger: 'blur'
					}],
					// 手机号
					mobile: [{
							required: true,
							message: '请输入手机号',
							trigger: ['change', 'blur'],
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								console.log('手机号码是否正确', value)
							},
							message: '手机号码不正确',
							// 触发器可以同时用blur和change
							trigger: ['change', 'blur'],
						}
					]
				}
			}
		},
		onLoad(options) {
			console.log('穿过爱的', options)
			if (options.isType) {
				this.isType = options.isType
			}
			console.log('获取判断类型', this.isType)
			let userInfo = uni.getStorageSync('userInfo');
			this.userInfo = userInfo,
				this.uid = userInfo ? userInfo[0].id : '',
				this.user_type = userInfo.user_type
			this.phone = userInfo[0].phone
			if (this.user_type == '自然人') {
				this.pageCount = 6
			} else {
				this.pageCount = 6
			}
			//  及时获取上传信息
			this.getUploadInfo();
		},
		methods: {
			// 获取上传信息
			getUploadInfo: function() {
				var that = this;
				uni.request({
					method: 'POST',
					url: 'https://jizhang.xqyu.cn/index.php/api/index/get_upload_info',
					dataType: 'json',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						uid: that.userInfo[0].id,
						user_type: that.userInfo.user_type
					},
					success: function(res) {
						console.log('获取上传结果', res)
						if (res.data.code == 1) {
							that.contract_one = res.data.data.contract_one,
								that.contract_two = res.data.data.contract_two,
								that.state = res.data.data.state,
								that.content = res.data.data.content
							// 更新时间
							that.updateTime = Validate.getYMDHMS((res.data.data.updatetime) * 1000)
							console.log('更新时间格式化', that.updateTime)
						} else {
							that.$.toast(res.data.msg)
						}
					}
				});
				console.log('状态', that.state)
			},

			uploadRqeust: function(file, file_type) {
				var that = this
				var strFile = file.join(',')
				console.log('获取传递过来的图片请求', file_type, file, strFile)
				uni.uploadFile({
					url: 'https://jizhang.xqyu.cn/index.php/api/index/upload',
					filePath: strFile,
					name: 'file',
					// 文件对应的key ，默认 为 file
					formData: {
						uid: that.uid,
						user_type: that.user_type,
						file: strFile,
						file_type: file_type
					},
					//上传额外携带的参数
					success(res) {
						console.log('获取最终是否成功上传后的东西', res.data)
						// 取消加载弹框
						that.$.hideLoading()
						let result = JSON.parse(res.data);
						if (result.code == 1) {
							that.$.successToast(result.msg);
							setTimeout(function() {
								uni.navigateBack({
									delta: 1
								});
							}, 2000); // 成功后返回上一个页面
						} else {
							that.$.toast(result.msg);
						}
					}
				});
			},
			// 上传合同
			uploadFileChange: function() {
				var that = this;
				uni.chooseMessageFile({
					success(res) {
						console.log('上传路径', res)
						that.$.tipLoading('上传中')
						if (res.errMsg == 'chooseMessageFile:ok') {
							var file = res.tempFiles
							var length = res.tempFiles.length
							var file_type = ''
							var newArr = []
							var PNG = false
							var JPG = false
							var JPEG = false
							var PDF = false
							var DOC = false
							var DOCX = false
							var OTHER = false
							file.forEach(item => {
								console.log('获取循环的数组', item.path)
								newArr.push(item.path)
							})
							console.log('newArr', newArr)
							newArr.forEach(item => {
								let type = item.substring(item.lastIndexOf('.'))
							.toLowerCase(); // 判断上传文件类型
								if (type == '.png') {
									PNG = true
								} else if (type == '.jpg') {
									JPG = true
								} else if (type == '.jpeg') {
									JPEG = true
								} else if (type == '.pdf') {
									PDF = true
								} else if (type == '.docx') {
									DOCX = true
								} else if (type == '.doc') {
									DOC = true
								} else {
									OTHER = true
								}
							})
							if ((DOCX || DOC || PDF) && (PNG || JPG || JPEG)) { //既上传图片又上传文件
								that.$.toast('pdf, doc或者docx和图片不能同时上传，');
							} else if (PNG || JPG || JPEG) { //只上传图片
								if (length < that.pageCount || length > that.pageCount) {
									that.$.toast('只能上传' + that.pageCount + '张图片');
								} else {
									file_type = 5
									var strFile = newArr.join(',')
									var count = 0;
									for (var i = 0; i < newArr.length; i++) {
										uni.uploadFile({
											url: 'https://jizhang.xqyu.cn/index.php/api/index/upload',
											filePath: newArr[i],
											name: 'file',
											// 文件对应的key ，默认 为 file
											formData: {
												uid: that.uid,
												user_type: that.user_type,
												file: newArr[i],
												file_type: file_type
											},
											//上传额外携带的参数
											success(res) {
												// 取消加载弹框
												that.$.hideLoading()
												let result = JSON.parse(res.data);
												console.log(result);
												count++;
												if (count == that.pageCount) {
													that.fileReal += result.data.url;
													//TODO 另一个接口
													uni.request({
														method: 'POST',
														url: 'https://jizhang.xqyu.cn/index.php/api/index/get_contract',
														dataType: 'json',
														header: {
															'content-type': 'application/x-www-form-urlencoded'
														},
														data: {
															user_type: that.userInfo.user_type,
															uid: that.userInfo[0].id,
															file_url: that.fileReal,
														},
														success: function(res) {
															let result = res.data;
															// //图片返回玲处理；
															if (result.code == 1) {
																that.$.successToast(result
																	.msg);
																setTimeout(function() {
																	uni.navigateBack({
																		delta: 1
																	});
																}, 2000); // 成功后返回上一个页面
															} else {
																that.$.toast(result.msg);
															}
														}
													})

												} else {
													that.fileReal += result.data.url + ","
												}
											},
											fail(err) {
												that.$.show(err.errMsg)
											}
										});
									}
								}
							} else if (DOCX || DOC || PDF) { //只上传文件
								file_type = 1 //只有文档是1
								console.log('走只有word', file)
								console.log('lenght', length)
								uni.uploadFile({
									url: 'https://jizhang.xqyu.cn/index.php/api/index/upload',
									filePath: newArr.join(),
									name: 'file',
									// 文件对应的key ，默认 为 file
									formData: {
										uid: that.uid,
										user_type: that.user_type,
										file: file,
										file_type: 1
									},
									//上传额外携带的参数
									success(res) {
										console.log('获取最终是否成功上传后的东西', res.data)
										// 取消加载弹框
										that.$.hideLoading()
										let result = JSON.parse(res.data);
										if (result.code == 1) {
											that.$.successToast(result.msg);
											setTimeout(function() {
												uni.navigateBack({
													delta: 1
												});
											}, 2000); // 成功后返回上一个页面
										} else {
											that.$.toast(result.msg);
										}
									},
									fail(err) {
										that.$.toast(err.errMsg);
									}
								});
							} else {
								that.$.toast('暂不支持其它格式文件');
							}
						}
					}
				});
			},
			// 电子签名
			uploadAutographChange: function() {
				uni.navigateTo({ //跳转电子签名页
					url: "../rate/index"
				});
			},
			// 确定提交
			formSubmit: function(e) {
				// 对象解构
				let {
					name,
					idcard,
					account,
					deposit
				} = e.detail.value;
				var obj = e.detail.value;
				if (!name) {
					this.$.toast('请输入户名');
					return;
				}
				if (!idcard) {
					this.$.toast('请输入身份证号');
					return;
				}
				if (!Validate.ValidateIdCard(idcard)) {
					this.$.toast('身份证号格式不正确');
					return;
				}
				if (!account) {
					this.$.toast('请输入银行账号');
					return;
				}
				if (!Validate.checkOpeningBankAccount(account)) {
					this.$.toast('银行账号格式不正确');
					return;
				}
				if (!deposit) {
					this.$.toast('请输入开户行');
					return;
				}
				var that = this;
				this.$.tipLoading('下载中')
				this.getAttachfile(obj); //调用下载函数
			},
			// 下载合同模板
			downLoadChange: function() {
				this.transhow = true
				// 只有自然人才能弹出身份新信息输入弹窗 联络人和法人不弹窗
				if (this.user_type === '法人' || this.user_type === '联络人') {
					console.log('走的是第一个')
					let obj = '';
					this.getAttachfile(obj); // this.getUploadInfo()// 重新调用获取上传附件信息
					uni.hideToast();
				} else {
					console.log('走的是第二个')
					// 弹出下载弹窗
					if (this.state == 0 || this.state == 1 || this.state == 2) {
						console.log('走的是第二个下面第一个')
						console.log('走0this.state == 0 || this.state == 1 || this.state == 2 ', this.state)
						// 显示下载弹窗
						this.isShowDownLoad = true
					} else {
						console.log('走的是第二个下面第二个')
						console.log('走其它state', this.state, this.contract_two)
						this.$.tipLoading("下载中")
						this.getUploadInfo(); // 重新调用获取上传附件信息
						this.upload(this.contract_one); //不需要弹窗直接下载
						this.$.hideLoading() //取消提示框
					}
				}
			},
			// 下载合同
			upload: function(url) {
				console.log('获取到即将下载的合同', url)
				var that = this
				this.$.tipLoading('下载中')
				uni.downloadFile({
					url: url,
					success: function(res) {
						const tempFilePath = res.tempFilePath;
						if (res.errMsg == 'downloadFile:ok') {} else {
							// 取消提示弹框
							uni.hideToast();
						} // 保存文件
						uni.saveFile({
							tempFilePath,
							success: function(res) {
								setTimeout(function() {
									// 取消提示弹框
									uni.hideToast();
									that.$.hideLoading();
								}, 4000);
								const savedFilePath = res.savedFilePath; // 打开文件
								console.log('路径', savedFilePath)
								uni.openDocument({
									filePath: savedFilePath,
									showMenu: true, //控制打开的word文档是否可以转发及分享
									success: function(res) {}
								});
							},
							fail: function(err) {}
						});
					},
					fail: function(err) {
						that.$.toast('下载合同失败' + err.errMsg, )
					}
				});
			},
			// 下载
			getAttachfile: function(obj) {
				console.log('获取传递过来的obj', obj)
				var that = this; // 调用下载
				uni.request({
					method: 'POST',
					url: 'https://jizhang.xqyu.cn/index.php/api/index/get_attachfile',
					dataType: 'json',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						user_type: that.userInfo.user_type,
						uid: that.userInfo[0].id,
						state: that.state,
						title: '自然人样本协议'
					},
					success: function(res) {
						// 关闭输入框弹窗
						that.isShowDownLoad = false
						// 取消下载弹窗
						setTimeout(function() {
							that.$.hideLoading()
						}, 2000);
						var URL = res.data.data.attachfile ? res.data.data.attachfile : res.data.data
							.contract_two;
						var FILE = res.data.data.file; // _self.downFile(url,obj)
						console.log('获取最后的参数', URL, FILE, res.data.data)
						if (res.data.code == 1) {
							if (that.user_type == '自然人') {
								if (that.state == 0 || that.state == 1 || that.state == 2) {
									//只有如果state状态是未上传状态，需要调用downFile函数 否则直接下载合同
									that.downFile(FILE, obj);
								} else {
									that.getUploadInfo(); // 重新调用获取上传附件信息
									that.upload(that.contract_one); //不需要弹窗直接下载
								}
							} else {
								if (that.state == 3) {
									console.log('走状态3')
									// 如果审核状态已通过直接调用getuploadinfo直接下载
									that.getUploadInfo();
									that.upload(that.contract_two);
								} else {
									console.log('走不是3的其它状态')
									// 直接调用下载打开文件
									that.upload(URL);
								}





							}
						}
					}
				});
			},
			downFile: function(url, obj) {
				var that = this;
				uni.request({
					method: 'POST',
					url: 'https://jizhang.xqyu.cn/index.php/api/index/downfile',
					dataType: 'json',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						user_type: that.userInfo.user_type,
						uid: that.userInfo[0].id,
						fileurl: url,
						name: obj.name,
						idcard: obj.idcard,
						account: obj.account,
						deposit: obj.deposit,
						phone: that.phone
					},
					success: function(res) {
						console.log('获取调用后的downfile', res)
						if (res.data.code == 1) {
							that.upload(res.data.data);
						}
					}
				});
			},
		},
		onReady: function() {},
	}
</script>

<style lang="scss">
	.form {

		// 覆盖uvie表单原有样式规则
		.u-form-item {

			// border: 2px solid green;
			.u-form-item__body {
				.u-form-item--left {
					// border: 2px solid green !important;//覆盖lebel边距
					width: 150rpx !important; //覆盖lebel边距

					.u-form-item--left__content {
						.u-form-item--left__content__label {
							width: 300rpx !important; //覆盖input边距
							margin-right: 50rpx !important; //覆盖input边距
						}
					}
				}

				.u-form-item--right {
					// border: 2px solid blue  !important;
					width: 300rpx !important;
				}
			}

		}
	}

	.con {
		margin: 20rpx 30rpx;
		border-radius: 10rpx;
		overflow: hidden;
		padding-bottom: 30rpx;
	}

	.title {
		display: block;
		padding: 15rpx 20rpx;
		font-weight: bold;
		// border-bottom: 1px #e5e5e5 solid;
	}

	.item {
		margin-top: 30rpx;
		padding: 0 20rpx;
	}

	.item image {
		width: 40rpx;
		height: 46rpx;
		margin-right: 20rpx;
	}

	.down {
		text-align: center;
		margin-right: 20rpx;
	}

	.down text {
		display: inline-block;
		background-color: #029ee9;
		border-radius: 10rpx;
		width: 178rpx;
		height: 60rpx;
		line-height: 60rpx;
	}

	.state {
		text-align: right;
		padding: 20rpx 30rpx;
		margin-top: 20rpx;
		justify-content: flex-end;
	}

	.state .del {
		color: #f51f02;
		line-height: 60rpx;
		margin-right: 40rpx;
	}

	.state .down1 {
		border: 1px #029ee9 solid;
		border-radius: 10rpx;
		width: 178rpx;
		height: 60rpx;
		line-height: 60rpx;
		color: #029ee9;
		margin-right: 20rpx;
	}

	.state .down {
		margin-right: 0;
	}

	.subbutton {
		background-color: #029ee9;
		color: #ffffff;
		font-size: 24rpx;
	}
</style>
